package com.yuanfeng.job.service.impl;

import com.yuanfeng.commoms.vo.order.CommissionSettleVO;
import com.yuanfeng.job.mapper.OrderCommissionMapper;
import com.yuanfeng.job.service.FXService;
import com.yuanfeng.job.service.PayFxTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @ClassName FXServiceImpl
 * @Description
 * @Author hyq
 * @Date 2023/9/5 13:19
 * @Version 1.0
 **/
@Service
public class FXServiceImpl implements FXService {

    @Autowired
    private PayFxTaskService payFxTaskService;
    @Autowired
    private OrderCommissionMapper orderCommissionMapper;
    @Override
    public void vkOrderCommission() {
        //1.查询所有过退货期还未结算的微客佣金订单
        List<CommissionSettleVO> commissionSettleList = orderCommissionMapper.queryOrderSettle(1);
        if(null != commissionSettleList && commissionSettleList.size() > 0 ) {
            for (CommissionSettleVO commissionSettle : commissionSettleList) {
                //计算佣金
                // 3.待结算佣金 购买人和分享人 是绑定关系的 订单
                BigDecimal settleCommission = orderCommissionMapper.querySettleAmount(commissionSettle.getShareUserId());
                if (null == settleCommission) {
                    settleCommission = new BigDecimal(0);
                }
                //购买人和分享人 不是绑定关系的 订单
                BigDecimal settleNotBindCommission = orderCommissionMapper.queryNotquerySettleAmount(commissionSettle.getShareUserId());
                if (null == settleNotBindCommission) {
                    settleNotBindCommission = new BigDecimal(0);
                }
                settleCommission = settleCommission.add(settleNotBindCommission);
                commissionSettle.setCommissionMoney(settleCommission);
            }
        }
        payFxTaskService.vkOrderCommission(commissionSettleList,1);
    }
}
